package com.woniu.user.service.impl;

import com.woniu.user.enity.dto.OperationLoginDTO;
import com.woniu.user.mapper.OperationMapper;
import com.woniu.user.pojo.Operation;
import com.woniu.user.service.IOperationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.woniu.user.util.AesUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;


import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;


/**
 * <p>
 * 运营端用户表 服务实现类
 * </p>
 *
 * @author LiFangyu
 * @since 2023-02-15
 */
@Slf4j
@Service
public class OperationServiceImpl extends ServiceImpl<OperationMapper, Operation> implements IOperationService {

    @Autowired(required = false)
    private OperationMapper operationMapper;
    /**
     * 登录功能
     * @param operationLoginDTO
     * @return
     */
    @Override
    public Operation operationLogin(OperationLoginDTO operationLoginDTO) {
       /* //1. 查询
        LambdaQueryWrapper<Operation> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Operation::getPhone, operationLoginDTO.getUsername());
        Operation one = getOne(wrapper);
        //2. 判断
        if (one == null) {
            Result.error("用户或密码错误！");
        }
        if (!one.equals(one.getPassword())) {
            Result.error("用户或密码错误！");
        }

        return one;*/
        String phone = operationLoginDTO.getUsername();
        String password = operationLoginDTO.getPassword();
        if (StringUtils.isEmpty(phone) || phone.length() != 11) {
            return null;
        }
        String encrypt = AesUtil.encrypt(password);
        Operation operation = operationMapper.login(phone,encrypt);
        return operation;
    }

}
